# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Wesley Moore <wes@wezm.net>

pkgname=difftastic
pkgver=0.46.0
_commit=cb9367c1298d253b4c2a0ec2536326abd388d043
pkgrel=1
pkgdesc='An experimental diff tool that compares files based on their syntax'
arch=('loong64' 'x86_64')
url='https://difftastic.wilfred.me.uk'
license=('MIT')
depends=('gcc-libs' 'shared-mime-info')
makedepends=('cargo' 'git' 'mdbook' 'jq')
source=("git+https://github.com/Wilfred/difftastic.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # download dependencies
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$pkgname"
  export CFLAGS+=" -ffat-lto-objects"

  # binary
  cargo build --frozen --release --all-features

  # documentation
  cd manual
  mdbook build
}

check() {
  cd "$pkgname"

  cargo test --frozen --all-features

  # run all ignored tests
  # https://github.com/Wilfred/difftastic/commit/34f21c6d9f256f16cc5f77294bcca9e61cee3fd6
  cargo test --frozen --all-features -- --ignored
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" target/release/difft

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
  cp -vr manual/book "$pkgdir/usr/share/doc/$pkgname/manual"

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
